package com.dhp.campus.contoller;

import com.dhp.campus.Common.Result;
import com.dhp.campus.Common.ResultUtils;
import com.dhp.campus.domain.Team;
import com.dhp.campus.domain.dto.TeamAddDTO;
import com.dhp.campus.domain.dto.showTeamsDTO;
import com.dhp.campus.domain.request.*;
import com.dhp.campus.domain.vo.teamsVO;
import com.dhp.campus.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/team")
public class TeamController {

    @Autowired
    private TeamService teamService;

    /**
     * 添加队伍
     * @param teamAddDTO
     * @param request
     * @return
     */
    @PostMapping("/add")
    public Result<Team> addTeam(@RequestBody TeamAddDTO teamAddDTO , HttpServletRequest request){
        Team addedTeam = teamService.addTeam(teamAddDTO , request);
        return ResultUtils.success(addedTeam);
    }


    /**
     * 队伍信息更新
     * @param teamUpdateRequest
     * @param request
     * @return
     */
    @PostMapping("/update")
    public Result<Boolean> teamUpdate(@RequestBody TeamUpdateRequest teamUpdateRequest , HttpServletRequest request){
        Boolean res = teamService.teamUpdate(teamUpdateRequest , request);
        return ResultUtils.success(res);
    }


    /**
     * 解散队伍
     * @param teamDeleteRequest
     * @param request
     * @return
     */
    @PostMapping("/delete")
    public Result<Boolean> deleteTeam(@RequestBody TeamDeleteRequest teamDeleteRequest, HttpServletRequest request){
        Boolean res = teamService.deleteTeam(teamDeleteRequest.getId() , request);
        return ResultUtils.success(res);
    }


    /**
     * 列举队伍
     * @param teamsDTO
     * @param request
     * @return
     */
    @GetMapping("/list")
    public Result<List<teamsVO>> showTeams(showTeamsDTO teamsDTO, HttpServletRequest request){
        List<teamsVO> teamsVOList = teamService.showTeams(teamsDTO , request);
        return ResultUtils.success(teamsVOList);
    }

    /**
     * 加入队伍
     * @param teamJoinRequest
     * @param request
     * @return
     */
    @PostMapping("/join")
    public Result<Boolean> joinTeam(@RequestBody TeamJoinRequest teamJoinRequest , HttpServletRequest request){
        Boolean res = teamService.joinTeam(teamJoinRequest , request);
        return ResultUtils.success(res);
    }

    @PostMapping("/quit")
    public Result<Boolean> quitTeam(@RequestBody TeamQuitRequest teamQuitRequest , HttpServletRequest request){
        boolean res = teamService.quitTeam(teamQuitRequest , request);
        return ResultUtils.success(res);
    }

    @GetMapping("/list/my/create")
    public Result<List<teamsVO>> searchMyTeam(MyTeamSearchRequest teamSearchRequest , HttpServletRequest request){
        List<teamsVO> res = teamService.searchMyTeam(teamSearchRequest , request);
        return ResultUtils.success(res);
    }

    @GetMapping("/list/my/join")
    public Result<List<teamsVO>> searchMyjoinTeam(showTeamsDTO showTeamsDTO , HttpServletRequest request){
        List<teamsVO> teamsVOList = teamService.searchMyjoinTeam(showTeamsDTO , request);
        return ResultUtils.success(teamsVOList);
    }



}
